package com.wuyou.hard;

import java.util.Arrays;
import java.util.Map;
import java.util.PriorityQueue;

/**
 * 3266. K 次乘运算后的最终数组 II
 *
 * @Date 2024/12/13 10:27
 * @Author 无忧
 */
public class GetFinalState {

    public static void main(String[] args) {
//        GetFinalState getFinalState = new GetFinalState();
        int[] nums = {2,1,3,5,6};
//        int k = 5;
//        int multiplier = 2;
//        int[] finalState = getFinalState.getFinalState1(nums, k, multiplier);
//        for(int x : finalState){
//            System.out.print(x + "\t");
//        }

        PriorityQueue<Integer> pq = new PriorityQueue<>((a, b) -> {
            if(nums[a] == nums[b]) {
                return a - b;
            }
            return nums[a] - nums[b];
        });
        pq.add(1);
        pq.add(2);
        pq.add(3);
//        System.out.println(pq.peek());
//        System.out.println(pq.size());
//        System.out.println(pq.poll());
//        System.out.println(pq.poll());
//        System.out.println(pq.poll());
//        System.out.println(pq.size());

        PriorityQueue<Integer> p = new PriorityQueue<>((a, b) -> {return a - b;});
        p.offer(4);
        p.offer(3);
        p.offer(2);
        p.offer(1);
        p.offer(5);
        System.out.println(p.poll());
        System.out.println(p.poll());
        System.out.println(p.poll());
        System.out.println(p.poll());
        System.out.println(p.poll());


    }

    public int[] getFinalState1(int[] nums, int k, int multiplier) {
        PriorityQueue<Integer> pq = new PriorityQueue<>((a, b)->{
            if(nums[a] == nums[b]) {
                return a - b;
            }
            return nums[a] - nums[b];
        });
        for(int i=0; i<nums.length; i++) {
            pq.offer(i);
        }
        while(k>0) {
            int idx = pq.poll();
            nums[idx]*=multiplier;
            pq.offer(idx);
            k--;
        }
        return nums;
    }
}
